package com.b511.swpu.cementbackend.controller;

import com.b511.swpu.cementbackend.dto.input.SysUserInputDto;
import com.b511.swpu.cementbackend.service.SysRoleService;
import com.b511.swpu.cementbackend.service.SysUserService;
import com.b511.swpu.cementbackend.util.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "新增员工", tags = {"新增员工"})
// 包含以下三个接口
// 新增员工
// 更新员工
// 用户授权(一个员工多个权限)
@RestController
@RequestMapping("/employee")
public class SysUserAddController {

    private final SysUserService sysUserService;

    public SysUserAddController(SysUserService userService){
        this.sysUserService = userService;
    }

    // 新增员工
    @PostMapping
    public R addUser(@RequestBody @Validated SysUserInputDto sysUserInputDto){
        return sysUserService.addUser(sysUserInputDto);
    }

    // 更新员工
    @PutMapping("/{id}")
    public R updateUser(@PathVariable String id,@RequestBody @Validated SysUserInputDto inputDto){
        return sysUserService.updateUser(id,inputDto);
    }

    // 用户授权
    @PutMapping("/role/{id}")
    public R updateRole(@PathVariable String id, @RequestBody @Validated SysUserInputDto inputDto){
        return sysUserService.updateUser(id,inputDto);
    }

}
